﻿using System;
using System.Web.Script.Services;
using System.Web.Services;
using MS.InformationManagement.BLL.UserProfileManagement;
using MS.InformationManagement.Support;
using MS.InformationManagement.Support.Constants;
using MS.InformationManagement.BLL.DocumentGenerator;

namespace MS.InformationManagement.Services
{
    /// <summary>
    /// Summary description for DocumentSchedulerService
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)] 
    [ScriptService]
    public class DocumentGeneratorService : System.Web.Services.WebService
    {
        [WebMethod]
        public bool DocumentExists(string fileName, string libraryID, string templatePath) {
            try
            {
                return DocumentGeneratorBLL.FileExists(fileName, new Guid(libraryID), templatePath);
            }
            catch (Exception ex)
            {
                Logger.LogException(ex, Microsoft.SharePoint.Administration.EventSeverity.Error,
                    SPDiagnosticsAreas.SHAREPOINTFOUNDATION, SPDiagnosticsAreas.SharepointFoundationDiagnosticsCategories.WEBPARTS);
                throw;
            }
        }

        [WebMethod]
        public string GenerateDocument(string fileName, string libraryID, string templatePath) {
            try
            {
                return DocumentGeneratorBLL.SaveDocument(fileName, new Guid(libraryID), templatePath);
            }
            catch (Exception ex)
            {
                Logger.LogException(ex, Microsoft.SharePoint.Administration.EventSeverity.Error,
                    SPDiagnosticsAreas.SHAREPOINTFOUNDATION, SPDiagnosticsAreas.SharepointFoundationDiagnosticsCategories.WEBPARTS);
                throw;
            }
        }
        
    }
}
